/**
 * Created by sa on 16-9-9.
 */
$(function () {
    function GetQueryString(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
    //媒体详情接口
    $.ajax({
        type:"GET",
        url:"http://api.headlines.video/api/media/info?media_id="+GetQueryString("media_id")+"&device_id=1",
        success:function (res) {
            var data= JSON.parse(res);
            var html = template("detail_media",data.data);
            $(".video_play").html(html);
            $(".back").on("click",function () {
                window.location.href="javascript:history.go(-1)";
            });
            $(".video_play .follow").on("click",function () {
                window.location.href="https://itunes.apple.com/us/app/chao-ji-tou-tiao/id1149308012?l=zh&ls=1&mt=8";
            });
        }
    });
    //媒体列表接口
    $.ajax({
        type:"GET",
        url:"http://api.headlines.video/api/media/video?media_id="+GetQueryString("media_id")+"&device_id=1",
        success:function (res) {
            var data= JSON.parse(res);
            var html = template("list_media",data);
            $(".video_list").html(html);
            $(".video_list ul li").on("click",function () {
                window.location.href="../html/index.html?video_id="+$(this).attr("_id")+"&device_id=1";
            });
        }
    })

});